﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace PhoneApp6
{
    public partial class Page2 : PhoneApplicationPage
    {
        public Page2()
        {
            InitializeComponent();
            if (App.nageri != "")
            {
                textBox1.Text = App.nageri.ToString();
                webBrowser1.Navigate(new Uri(App.nageri.ToString()));

            }
        }
        private void webBrowser1_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
        { }
        private void webBrowser1_ScriptNotify(object sender, NotifyEventArgs e)
        {
            MessageBox.Show(e.Value.ToString());
        }

        private void webBrowser1_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            textBox1.Text = e.Uri.ToString();
            App.nageri = e.Uri.ToString();
        }
        private void webBrowser1_Navigating(object sender, NavigatingEventArgs e)
        {
            string uorg = e.Uri.ToString();
            if (uorg.Trim().EndsWith("rar") || uorg.Trim().EndsWith("zip") || uorg.Trim().EndsWith("iso") || uorg.Trim().EndsWith("pdf") || uorg.Trim().EndsWith("rmvb") || uorg.Trim().EndsWith("avi") || uorg.Trim().EndsWith("mp4") || uorg.Trim().EndsWith("torrent") || uorg.Trim().EndsWith("mkv") || uorg.Trim().EndsWith("exe") || uorg.Trim().EndsWith("mp3"))
            {

                if (MessageBox.Show(e.Uri.ToString(), "确定下载此文件？", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    NavigationService.Navigate(new Uri("/Page1.xaml?flstr="+uorg, UriKind.Relative));
                }
                else { return; }
            }
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            webBrowser1.InvokeScript("eval", "history.go(-1)");
        }

        private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
        {

        }

        private void ApplicationBarIconButton_Click(object sender, EventArgs e)
        {
            webBrowser1.Navigate(new Uri(textBox1.Text.ToString()));
        }

        private void ApplicationBarIconButton_Click_1(object sender, EventArgs e)
        {
            webBrowser1.InvokeScript("eval", "history.go(-1)");
        }

        private void ApplicationBarIconButton_Click_2(object sender, EventArgs e)
        {
            webBrowser1.InvokeScript("eval", "history.go(1)");
        }

        private void ApplicationBarIconButton_Click_3(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/Page1.xaml?flstr=", UriKind.Relative));
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                webBrowser1.Navigate(new Uri(textBox1.Text.ToString()));
                this.Focus();
            }

        }
    }
}